using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using DTO;

namespace DAO
{
    public class XeDAO
    {

        public static DataTable LayThongTinTinhTrangXe()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTinhTrangXeCungCap", null);
            return dt;
        }
        public static DataTable LayThongTinXe()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinXe", null);
            return dt;
        }
        public static DataTable LayThongTinTrongTai()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTrongTai", null);
            return dt;
        }
        public static DataTable LayThongTinHangXe()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinHangXe", null);
            return dt;
        }
        public static DataTable LayThongTinLoaiXe()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinLoaiXe", null);
            return dt;
        }
        public static DataTable LayThongTinLoaiHangCho()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinLoaiHangCho", null);
            return dt;
        }
        public static bool NhapXeMoi(XeDTO xe)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@NgayTiepNhan", xe.NgayTiepNhan));
                sqlParams.Add(new SqlParameter("@NVTiepNhan", xe.NVTiepNhan));
                sqlParams.Add(new SqlParameter("@BienSo", xe.BienSo));
                sqlParams.Add(new SqlParameter("@TrongTai", xe.TrongTai));
                sqlParams.Add(new SqlParameter("@HangXe", xe.HangXe));
                sqlParams.Add(new SqlParameter("@NamSX", xe.NamSX));
                sqlParams.Add(new SqlParameter("@LoaiXe", xe.LoaiXe));
                sqlParams.Add(new SqlParameter("@MaLoaiHang", xe.MaLoaiHangCho));

                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertXe", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool KiemTraNhapXeMoi(String BienSo)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@BienSO", BienSo));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapXeMoi", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}
